//
//  YTDHButton.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/10.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTDHButton.h"

#define kYTButtonNormalColor [UIColor colorWithRed:165.0f/255.0f green:176.0f/255.0f blue:177.0f/255.0f alpha:1]
@interface YTDHButton ()
@property (weak, nonatomic) IBOutlet UILabel *txtLabel;
@property (weak, nonatomic) IBOutlet UIView *tipView;

@property(nonatomic ,strong)UIColor *selectedColor;

@end
@implementation YTDHButton

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    
    self.tipView.backgroundColor = selected ? kMainColor : UIColor.whiteColor;
    self.txtLabel.textColor = selected ? kMainColor : UIColor.blackColor;
    //self.txtLabel.font = selected ? [UIFont boldSystemFontOfSize:12] : [UIFont systemFontOfSize:14];
    
    if (selected) {
        [UIView animateWithDuration:0.1 animations:^{
            self.txtLabel.font = [UIFont boldSystemFontOfSize:16];
        }];
    }else{
        [UIView animateWithDuration:0.1 animations:^{
            self.txtLabel.font = [UIFont systemFontOfSize:14];
        }];

    }
}

// 实例化方法
+ (instancetype)dh_buttonWithFrame:(CGRect)frame
                             title:(NSString *)title
                     selectedColor:(UIColor *)selectedColor
{
    UINib *nib = [UINib nibWithNibName:@"YTDHButton" bundle:nil];
    
    YTDHButton *btn = [nib instantiateWithOwner:nil options:nil][0];
    btn.txtLabel.text = title;
    btn.frame = frame;
    btn.selectedColor = selectedColor;
    return btn;
}
@end
